﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;

namespace YouDaoNotesCodes.CSharp_highLevel
{
    class UseCache
    {
        public void getCache()
        {
            //插入缓存
            DateTime dt = DateTime.Now.AddSeconds(1 * 24 * 60 * 60);
            SetRuntimeCache("ZWQ", "1214", dt);
            SetRuntimeCache("WQ", "12114", dt);

            //获取
            var getCatch = GetRuntimeCache("ZWQ");
            Console.WriteLine(HttpRuntime.Cache.Get("ZWQ"));
            Console.ReadKey();
        }


        /// <summary>

        /// 获得缓存

        /// </summary>

        /// <param name="cacheName"></param>

        /// <returns></returns>

        public static object GetRuntimeCache(string cacheName)
        {

            return HttpRuntime.Cache[cacheName];

        }



        /// <summary>

        /// 更新插入缓存

        /// </summary>

        /// <param name="cacheName"></param>

        /// <param name="value"></param>

        /// <param name="expiresAt"></param>

        public static void SetRuntimeCache(string cacheName, object value, DateTime expiresAt)
        {

            HttpRuntime.Cache.Add(cacheName, value, null, DateTime.Now.AddSeconds(1*24*60*60), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

        }
    }
}
